Golang 入门系列(十一)Go语言实现webapi 您所在的位置:网站首页 go语言 web开发 Golang 入门系列(十一)Go语言实现webapi

Golang 入门系列(十一)Go语言实现webapi

2024-01-18 20:40| 来源: 网络整理| 查看: 265

package controller

import ( "net/http" "micro-cloud/service" "micro-cloud/utils" "micro-cloud/framework")

/** * r.PostFormValue : 可以解析 Post/PUT Content-Type=application/x-www-form-urlencoded 或 Content-Type=multipart/form-data */

type UserConterller struct {

}

var userService = new(service.UserService)

func (p *UserConterller) Router(router *framework.RouterHandler) { router.Router("/register", p.register) router.Router("/login", p.login) router.Router("/findAll", p.findAll)}

//POST Content-Type=application/x-www-form-urlencodedfunc (p *UserConterller) register(w http.ResponseWriter, r *http.Request) { username := r.PostFormValue("username") password := r.PostFormValue("password") if utils.Empty(username) || utils.Empty(password) { microcloud.ResultFail(w, "username or password can not be empty") return } id := userService.Insert(username, password) if id



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有